package com.example.springboot.config;

import java.util.HashMap;
import java.util.Map;

public class Result extends HashMap<String,Object> {

    public Result() {
        put("code","0000");
        put("msg","success");
    }

    public static Result error() {
        return error(1000,"未知异常，联系管理员");
    }

    public static Result error(String msg) {
        return error(1000,msg);
    }

    public static Result unLoginError() {
        return error(1000,"登录异常");
    }

    public static Result error(int code,String msg) {
        Result result = new Result();
        result.put("code",code);
        result.put("msg",msg);
        return result;
    }

    public static Result ok(String msg) {
        Result r = new Result();
        r.put("code", "0000");
        r.put("msg", msg);
        return r;
    }

    public static Result ok(Map<String, Object> map) {
        Result r = new Result();
        r.putAll(map);
        return r;
    }

    public static Result ok(Object object) {
        Result r = new Result();
        r.put(object);
        return r;
    }

    public static Result ok() {
        return new Result();
    }

    @Override
    public Result put(String key, Object value) {
        super.put(key, value);
        return this;
    }

    public Result put(Object value) {
        super.put("data", value);
        return this;
    }
}
